package com.gqh.weather.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册Sa-Token拦截器，校验所有请求是否登录
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/pingjia/zh/v1/**")
                .excludePathPatterns(
                        "/pingjia/zh/v1/account/login", // 登录接口不需要认证
                        "/pingjia/zh/v1/yj/login", // 登录接口不需要认证
                        "/pingjia/zh/v1/exam/student/login", // 学生登录
                        "/pingjia/zh/v1/exam/student/submit", // 学生交卷
                        "/error", // 错误页面
                        "/health/check", // 错误页面
                        "/actuator/**" // Spring Boot Actuator接口
                );
    }
}